<template>
	<view class="container">
		<view class="main">
			<u--form labelPosition="top" labelWidth="auto" :model="model" :rules="rules" ref="form">
				<u-form-item label="今日体温：" prop="temperature" borderBottom>
					<u--input v-model="model.temperature" disabledColor="#ffffff" type="digit" 
						placeholder="请输入当前体温(34℃~42℃)" border="none" >
					</u--input>
				</u-form-item>
				<u-form-item label="今日健康码颜色：" prop="radiovalue1" borderBottom>
					<u-radio-group v-model="model.radiovalue1" placement="row">
						<u-radio :customStyle="{marginBottom: '8px'}" v-for="(item, index) in radiolist1" :key="index"
							:label="item.name" :name="item.name" size="30" labelSize="30" iconSize="28"
							@change="groupChange(item)">
						</u-radio>
					</u-radio-group>
				</u-form-item>
				<u-form-item label="本人健康状况：" prop="radiovalue2" borderBottom>
					<u-radio-group v-model="model.radiovalue2" placement="row">
						<u-radio size="30" labelSize="30" iconSize="28" :customStyle="{marginBottom: '8px'}"
							v-for="(item, index) in radiolist2" :key="index" :label="item.name" :name="item.name"
							@change="radioChange(item)">
						</u-radio>
					</u-radio-group>
				</u-form-item>
			</u--form>
			<u-gap height="64"></u-gap>
			<u-button type="primary" text="修改" @click="submit()"></u-button>
			<u-gap height="32"></u-gap>
		</view>
	</view>
</template>

<script>
	import api from '@/api/api.js';
	export default {
		data() {

			return {
				healthCodeColor: null,
				healthStatus: null,
				groupid: 1,
				radioid: 1,
				texta: '温馨提示：健康填报每天仅有一次填写！',


				radiolist1: [{
						name: '绿色',
						id: 1,
						disabled: false
					},
					{
						name: '黄色',
						id: 2,
						disabled: false
					},
					{
						name: '红色',
						id: 3,
						disabled: false
					}
				],
				radiolist2: [{
						name: '正常',
						id: 1,
						disabled: false
					},
					{
						name: '异常',
						id: 2,
						disabled: false
					}
				],
				model: {
					radiovalue1: '绿色',
					radiovalue2: '正常',
					temperature: null,
				},
				rules: {
					temperature: [{
						type: 'string',
						required: true,
						message: '体温限制范围(34℃~42℃)',
						trigger: ['blur', 'change']
					}],
					radiovalue1: [{
						type: 'string',
						required: true,
						message: '请选择今日健康码',
						trigger: ['blur', 'change']
					}],
					radiovalue2: [{
						type: 'string',
						required: true,
						message: '请选择健康状况',
						trigger: ['blur', 'change']
					}],
				},
				id:null
			};
		},
		onLoad(option) {
			if (option.id != undefined) {
				this.id = option.id
				this.getDetails()
			}
		},
		
		methods: {
			// 获取健康详情
			getDetails(){
				let data={
					id:this.id
				}
				api.getReportInfo(data).then(res=>{
					console.log('详情数据',res)
					if(res.data.code==200){
						let data = res.data.data
						this.model.temperature = data.bodyTemperature
						this.model.radiovalue1 = data.healthCodeColor===1 ? '绿色':(data.healthCodeColor===2 ? '黄色':'红色')
						this.model.radiovalue2 = data.healthStatus===1 ? '正常':'异常'
					}
				})
			},
			groupChange(item) {
				console.log(item);
				this.groupid = item.id
				console.log(this.groupid)
			},
			radioChange(item) {
				this.radioid = item.id
			},
			// onlyNum(model) {
			// 	console.log('model', model)
			// 	if (model.temperature < 34 || model.temperature > 42) {
			// 		uni.$u.toast('体温限制范围(34℃~42℃)')
			// 		console.log(model.temperature)
			// 		model.temperature=null
			// 	} //执行至该语句时，阻止输入；可类比阻止冒泡原理或者禁止右键功能；
			// },
			// 点击提交
			submit() {
				this.$refs.form.validate().then(res => {
					let userInfo = uni.getStorageSync('userInfo')
					let data = {
						userId: userInfo.id,
						bodyTemperature: this.model.temperature,
						healthCodeColor: this.groupid,
						healthStatus: this.radioid,
					}
					if (this.model.temperature >=34&&this.model.temperature <=42) {
						
						api.healthAdd(data).then(res => {
							console.log('新增', res)
							if (res.data.code == 200) {
								uni.$u.toast('提交成功')
								uni.$u.route({
									type: "navigateBack",
									url: "/pages/service/list"
								});
							}
						})
					}else{
						this.model.temperature=null
						uni.$u.toast('体温不符，提交失败')
					}
				})
			},
		}
	};
</script>
<style lang="scss">
	.container {
		width: calc(100% - 32rpx);
		padding: 0 16rpx;
	}

	.tabsContent {
		margin-top: 16rpx;
		width: 100%;
		background-color: #FFFFFF;
		height: 600rpx;
	}

	.main {
		width: calc(100% - 64rpx);
		padding: 16rpx 32rpx;
		border-radius: 8rpx;
		background-color: #FFFFFF;
		margin: 16rpx 0;
	}

	.topA {
		display: flex;
		flex-direction: row !important;
	}
</style>
